using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

namespace revoStore
{
    public class AppOld
    {
        #region "Proprietes"
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _version;
        public string Version
        {
            get { return _version; }
            set { _version = value; }
        }

        private string _creator;
        public string Creator
        {
            get { return _creator; }
            set { _creator = value; }
        }

        private string _type;
        public string Type
        {
            get { return _type; }
            set { _type = value; }
        }

        private string _setupFile;
        public string SetupFile
        {
            get { return _setupFile; }
            set { _setupFile = value; }
        }

        private byte[] _setup;
        public byte[] Setup
        {
            get { return _setup; }
            set { _setup = value; }
        }

        private string _uninstFile;
        public string UninstFile
        {
            get { return _uninstFile; }
            set { _uninstFile = value; }
        }

        private byte[] _uninstall;
        public byte[] Uninstall
        {
            get { return _uninstall; }
            set { _uninstall = value; }
        }

        private int _ID;
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private string _filepath;
        public string FilePath
        {
            get { return _filepath; }
            set { _filepath = value; }
        }

        private string _directx;
        public string DirectXPath
        {
            get { return _directx; }
            set { _directx = value; }
        }

        private byte[] _directxsetup;
        public byte[] DirectXSetup
        {
            get { return _directxsetup; }
            set { _directxsetup = value; }
        }

        private string _vcr;
        public string VCRPath
        {
            get { return _vcr; }
            set { _vcr = value; }
        }

        private byte[] _vcrsetup;
        public byte[] VCRSetup
        {
            get { return _vcrsetup; }
            set { _vcrsetup = value; }
        }
        #endregion


        public bool down = false;



        public AppOld(string packageFile, bool fromCode)
        {
            if (!fromCode)
            {
                XML x = new XML(packageFile, false);

                this.Name = x.GetNodeContent("name");
                this.Version = x.GetNodeContent("version");
                this.Creator = x.GetNodeContent("creator");
                this.Type = x.GetNodeContent("type");
                this.DirectXPath = x.GetNodeContent("directx");
                var g = @x.@GetNodeContent("setup");
                //System.Windows.Forms.MessageBox.Show(g);
                if (g.StartsWith("./"))
                {
                    g = g.Replace("./", "");
                }
                else if (g.StartsWith("URL:"))
                {
                    down = true;
                    g = g.Replace("URL:", "");
                }

                this.SetupFile = g;
                var g2 = @x.@GetNodeContent("uninstall");
                //System.Windows.Forms.MessageBox.Show(g);
                if (g2.StartsWith("./"))
                {
                    g2 = g.Replace("./", "");
                }
                else if (g2.StartsWith("URL:"))
                {
                    down = true;
                    g2 = g2.Replace("URL:", "");
                }
                this.UninstFile = g2;
                /*string g = x.GetNodeContent("setup");
                if (g.StartsWith("./"))
                {

                }
                this.Setup = System.IO.File.ReadAllBytes(x.GetNodeContent("setup"));
                this.Uninstall = System.IO.File.ReadAllBytes(x.GetNodeContent("uninstall"));*/
                this.FilePath = packageFile;
                int i;
                if (Int32.TryParse(x.GetNodeContent("id"), out i))
                {
                    this.ID = Int32.Parse(x.GetNodeContent("id"));
                }
                else
                {

                }
            }
            else
            {
                XML x = new XML(packageFile, true);

                this.Name = x.GetNodeContent("name");
                this.Version = x.GetNodeContent("version");
                this.Creator = x.GetNodeContent("creator");
                this.Type = x.GetNodeContent("type");
                var g = @x.@GetNodeContent("setup");
                //System.Windows.Forms.MessageBox.Show(g);
                if (g.StartsWith("./"))
                {
                    g = g.Replace("./", "");
                }
                else if (g.StartsWith("URL:"))
                {
                    down = true;
                    g = g.Replace("URL:", "");
                }
                this.SetupFile = g;
                var g2 = @x.@GetNodeContent("uninstall");
                //System.Windows.Forms.MessageBox.Show(g);
                if ((g2 == null) || (string.IsNullOrEmpty(g2)) || (string.IsNullOrWhiteSpace(g2)))
                {
                    this.UninstFile = null;
                }
                else
                {
                    if (g2.StartsWith("./"))
                    {
                        g2 = g.Replace("./", "");
                    }
                    else if (g2.StartsWith("URL:"))
                    {
                        down = true;
                        g2 = g2.Replace("URL:", "");
                    }
                    this.UninstFile = g;
                }
               /* this.Setup = System.IO.File.ReadAllBytes(x.GetNodeContent("setup"));
                this.Uninstall = System.IO.File.ReadAllBytes(x.GetNodeContent("uninstall"));*/
                this.FilePath = packageFile;
                int i;
                if (Int32.TryParse(x.GetNodeContent("id"), out i))
                {
                    this.ID = Int32.Parse(x.GetNodeContent("id"));
                }
                else
                {

                }
            }
        }



        /*public App(Int32 id)
        {
            SQL sq = new SQL(revoStore.Vars.sqlHost, revoStore.Vars.sqlUser, revoStore.Vars.sqlPass, revoStore.Vars.sqlDB);

            string query = "SELECT * FROM apps WHERE ID='" + id + "'";

            dynamic g = sq.GetRow(query);

            this.ID = g(0);
            this.Name = g(1);
            this.Version = g(2);
            this.Creator = g(3);
            this.Type = g(4);
            this.Setup = g(5);
        }*/
    }
}